//
//  HMBaseViewController.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/4/9.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import RKDropdownAlert

public typealias HMViewController = HMBaseViewController

public class HMBaseViewController: UIViewController {
    //MARK: - 变量
    public var _signStr = "" //标记
    public var info = NSDictionary() //这个view的数据
    public var isHideNavigationBar: Bool = false // 隐藏导航条？ - false
    
    //MARK: - 周期
    override public func viewDidLoad() {
        super.viewDidLoad()
        self.setupView()
    }
    override public func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if isHideNavigationBar {
            self.navigationController?.setNavigationBarHidden(true, animated: animated)
        }else {
            self.navigationController?.navigationBar.isTranslucent = false //是半透明的
            self.navigationController?.setNavigationBarHidden(false, animated: animated)
        }
    }
    override public func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        //处理可重新创建的任何资源。
    }
    // MARK: - setupView
    public func setupView() {
//        self.title = "登录页面"
//        self.view.translatesAutoresizingMaskIntoConstraints = false
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

public extension UIViewController {
    /**
     * push 下一个 vc
     */
    public func pushViewController(_ viewController: UIViewController, animated: Bool = true) {
        if let nav = self.navigationController {
            viewController.hidesBottomBarWhenPushed = true
//            nav.pushViewController(viewController, animated: animated)
            nav.pushViewController(viewController)
        }
    }
}


public extension UIView {
    /**
     *  设置是否手动添加布局 - false = YES , true = NO, 默认允许
     */
    public func setAutoLayout(allow: Bool = false) {
        if self.subviews.count > 0 {
            for subV in self.subviews {
                subV.setAutoLayout(allow: allow)
            }
        }
        self.translatesAutoresizingMaskIntoConstraints = allow
    }
}

public extension HMBaseViewController {
    func keyBordNotification(this: UIViewController, aShow: Selector, aHide: Selector){
        NotificationCenter.default.addObserver(this, selector: aShow, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
        NotificationCenter.default.addObserver(this, selector: aHide, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
    }
    
    
    func openButtonRecognition(setStyleBtn: UIButton, isOpen: Bool) {
        if isOpen {
            setStyleBtn.isEnabled = isOpen
            setStyleBtn.backgroundColor = configure.shareConfigure.HMColor1
//            setStyleBtn.layer.borderColor = configure.shareConfigure.HMColor1.cgColor
        }else {
            setStyleBtn.isEnabled = isOpen
            setStyleBtn.backgroundColor = UIColor.RGBA(r: 180, g: 180, b: 180, a: 1)
//            setStyleBtn.layer.borderColor = UIColor.RGBA(r: 180, g: 180, b: 180, a: 1).cgColor
        }
    }
    
    // 在调用该方法的地方添加
//
//        deinit {
//            NotificationCenter.default.removeObserver(this)
//        }
//
    
}



